<?php
/**
 * Template Name: My Account
 */

get_header(); ?>

<div class="container">
    <h1><?php the_title() ?></h1>

    <div class="row-fluid">
        <div class="span4">
            <div class="card grey">
                <a class="btn btn-primary pull-right">Edit Details &raquo;</a>

                <h2 class="title">My Details</h2>

                <form id="my-details" style="margin:0;">
                    <fieldset>
                        <label>Username</label>
                        <? echo get_userdata(get_user_id())->user_login;  ?>
                        <span class="help-block"></span>
                    </fieldset>
                    <fieldset>
                        <label>Email</label>
                        <? echo get_userdata(get_user_id())->user_email;  ?>
                        <span class="help-block"></span>
                    </fieldset>
                    <fieldset>
                        <label>First Name</label>
                        <? echo get_user_meta(get_user_id(), 'first_name', true);  ?>
                        <span class="help-block"></span>
                    </fieldset>
                    <fieldset>
                        <label>Last Name</label>
                        <? echo get_user_meta(get_user_id(), 'last_name', true);  ?>
                        <span class="help-block"></span>
                    </fieldset>
                </form>
            </div>
        </div>
        <div class="span8">
            <div class="card grey">
                <h2 class="title">My Bookings</h2>

                <table class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>Venue</th>
                        <th>Pitch</th>
                        <th>Start</th>
                        <th>End</th>
                        <th>Date</th>
                    </tr>
                    </thead>
                    <tbody>

                    <?
                    $booking_query = new WP_Query(array('post_type' => 'bookings', 'showposts' => 100));
                    while ($booking_query->have_posts()) : $booking_query->the_post();
                        //$temp = get_post_meta($booking_query->post->ID, 'slot', true);

                        $temp = get_field('slot', $booking_query->post->ID);
                        $slotid = $temp[0]->ID;
                        $temp = get_field('pitch', $slotid);
                        $pitchid = $temp[0]->ID;
                        $temp = get_field('venue', $pitchid);
                        $venueid = $temp[0]->ID;
                        if (get_field('customer_id', $booking_query->post->ID) == get_user_id()) {
                            ?>

                        <tr>
                            <td><a href="<? echo get_permalink($venueid) ?>"><? the_field('name', $venueid); ?></a></td>
                            <td><a href="<? echo get_permalink($pitchid) ?>"><? the_field('pid', $pitchid); ?></a></td>
                            <td><? the_field('start_time', $slotid); ?></td>
                            <td><? the_field('end_time', $slotid); ?></td>
                            <td><?

                                $date = DateTime::createFromFormat('Ymd', get_field('date', $booking_query->post->ID));
                                echo $date->format('l, d M Y');
                                ?></td>

                        </tr>
                            <?
                        }
                    endwhile;
                    ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>


<?php get_footer(); ?>